<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta name="description" content="Xenon Boostrap Admin Panel" />
	<meta name="author" content="" />
	
	<title>DISTRA-MIT</title>
	
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Arimo:400,700,400italic">
	<link rel="stylesheet" href="assets/css/fonts/linecons/css/linecons.css">
	<link rel="stylesheet" href="assets/css/fonts/fontawesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="assets/css/bootstrap.css">
	<link rel="stylesheet" href="assets/css/xenon-core.css">
	<link rel="stylesheet" href="assets/css/xenon-forms.css">
	<link rel="stylesheet" href="assets/css/xenon-components.css">
	<link rel="stylesheet" href="assets/css/xenon-skins.css">
	<link rel="stylesheet" href="assets/css/custom.css">

	<script src="assets/js/jquery-1.11.1.min.js"></script>
	<script>
		jQuery(document).ready(function($){
			if(localStorage.getItem("username")!=null){
				if(localStorage.getItem("typology")=="Professore"){
					window.location.replace("offertaFormativaProfessore.html");
				}
				if(localStorage.getItem("typology")=="Studente"){
					window.location.replace("offertaFormativaStudente.html");
				}
				if(localStorage.getItem("typology")=="Organizzazione"){
					window.location.replace("gestioneTirocinio&PlacementOrganizzazione.html");
				}
				if(localStorage.getItem("typology")=="Amministratore"){
					window.location.replace("offertaFormativaAmministratore.html");
				}
			}
		});
	</script>

	<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!--[if lt IE 9]>
		<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
		<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
	<![endif]-->
	
	
</head>
<body class="page-body">
	<nav class="navbar horizontal-menu navbar-fixed-top"><!-- set fixed position by adding class "navbar-fixed-top" -->
		
		<div class="navbar-inner">
		
			<!-- Navbar Brand -->
			<div class="navbar-brand">
				<a href="index.html" class="logo">
					<img src="assets/images/mitforsite.png" width="80" alt="" class="hidden-xs" />
					<img src="assets/images/mitforsitemini.png" width="80" alt="" class="visible-xs" />
				</a>
			</div>
				
			<!-- Mobile Toggles Links -->
			<div class="nav navbar-mobile">
			
				<!-- This will toggle the mobile menu and will be visible only on mobile devices -->
				<div class="mobile-menu-toggle">
					
					<a href="#" data-toggle="user-info-menu-horizontal">
						<i class="fa-key"></i>
					</a>
					
					<a href="#" data-toggle="mobile-menu-horizontal">
						<i class="fa-bars"></i>
					</a>
				</div>
			</div>
			
			<div class="navbar-mobile-clear"></div>
			
			<!-- main menu -->
					
			<ul class="navbar-nav">
				<li>
					<a href="index.html">
						<i class="fa fa-home"></i>
						<span class="title">Home</span>
					</a>
				</li>
				<li>
					<a href="offertaFormativa.html">
						<i class="linecons-desktop"></i>
						<span class="title">Offerta Formativa</span>
					</a>		
				</li>
				<li>
					<a href="gestioneTesi.html">
						<i class="linecons-graduation-cap"></i>
						<span class="title">Gestione Tesi</span>
					</a>
				</li>
				<li>
					<a href="gestioneTirocinio.html">
						<i class="linecons-megaphone"></i>
						<span class="title">Gestione Tirocinio</span>
					</a>
				</li>
				<li>
					<a href="dottorato.html">
						<i class="linecons-lightbulb"></i>
						<span class="title">Dottorato</span>
					</a>
				</li>
                <li>
				    <a href="#">
				        <i class="linecons-globe"></i>
						<span class="title">Links</span>
					</a>
					<ul>
						<li>
							<a href="http://www.magistralemit.unisa.it/" target="_blank">
								<span class="title">DISTRA-MIT</span>
							</a>
						</li>
						<li>
							<a href="https://esse3web.unisa.it/unisa/Start.do" target="_blank">
								<span class="title">Esse3</span>
							</a>
						</li>
					</ul>
                </li>
			</ul>
            
					
			
			<!-- notifications and other links -->
			<ul class="nav nav-userinfo navbar-right">
                <li class="opened active">
				    <a href="login.html">
				        <i class="fa-user"></i>
						<span class="title">Login</span>
					</a>
                </li>
			</ul>
	
		</div>
		
	</nav>
    <!--BODY-->
    
    <div class="page-container">
        <div class="main-content">
            <div class="col-sm-2"></div>
            <div class="col-sm-8">
				<div class="panel panel-default">
				
					<div class="panel-heading">
						<h3 class="panel-title">Accedi a MITPlatform</h3>
					</div>
					
					<div class="panel-body">
						<form>
						
							<div id="form-group-username" class="form-group">
								<label>Username:</label>
								<div class="input-group">
									<span class="input-group-addon"><i class="fa-user"></i></span>
									<input type="text" id="username" class="form-control" placeholder="Inserisci lo username" />
								</div>
								<span id="validate_username" style="color:#cc3f44"></span>
							</div>
							
							<div class="form-group">
								<label>Password:</label>
								<div class="input-group">
									<span class="input-group-addon"><i class="fa-key"></i></span>
									<input type="password" id="password" class="form-control" placeholder="Inserisci la password" />
								</div>
								<span id="validate_password" style="color:#cc3f44"></span>
							</div>
							
							<div class="form-group">
								<label>
									<input type="checkbox" class="cbr cbr-done" id="rememberMeForLogin" checked>
									Ricordami la prossima volta
								</label>
							</div>
							
							<div class="col-sm-12">
								<div id="messageControl" align="center">
								</div>
							</div>
							
							<div class="form-group">
								<button type="button" id="signin" class="btn btn-blue">Sign in</button>
								<button type="reset"  id="reset"  class="btn btn-white">Reset</button>
							</div>
						</form>
						
					</div>
				</div>
				</div>
            <div class="col-sm-2"></div>
        </div>
    </div>

	
	<!-- Bottom Scripts -->
	<script src="assets/js/bootstrap.min.js"></script>
	<script src="assets/js/TweenMax.min.js"></script>
	<script src="assets/js/resizeable.js"></script>
	<script src="assets/js/joinable.js"></script>
	<script src="assets/js/xenon-api.js"></script>
	<script src="assets/js/xenon-toggles.js"></script>
	<script src="assets/js/jquery-ui/jquery-ui.min.js"></script>

	<!-- Imported scripts on this page -->
	<script src="assets/js/tocify/jquery.tocify.min.js"></script>
	
	<!-- Imported scripts on this page -->
	<script src="assets/js/jquery-validate/jquery.validate.min.js"></script>

	<!-- JavaScripts initializations and stuff -->
	<script src="assets/js/xenon-custom.js"></script>
	
	<script>
		function reset(){
			$("#password").attr("style","border-color:#e4e4e4;");
			$("#validate_password").html("");
			$("#username").attr("style","border-color:#e4e4e4;");
			$("#validate_username").html("");
			$("#username").val("");
			$("#password").val("");
			$("#messageControl").removeAttr("class");
			$("#messageControl").empty();
		}
		
		function emptyControl(id){
			if($("#"+id).val() == "")
				return false;
			return true;
		}
		
		function checkNotEmptyFields(){
			var tmp1 = emptyControl("username");
			var tmp2 = emptyControl("password");
			if(!tmp1) {
				$("#validate_username").html("Campo username vuoto");
				$("#username").attr("style","border-color:#cc3f44;");
			}
			if(!tmp2) {
				$("#validate_password").html("Campo password vuoto");
				$("#password").attr("style","border-color:#cc3f44;");
			}
			
			return tmp1&tmp2;
		}
		
		jQuery(document).ready(function($){
		
			$("#reset").click(function(){
				reset();
			});
			
			$("#username").keyup(function(){
				$("#username").attr("style","border-color:#e4e4e4;");
				$("#validate_username").html("");
			});
			
			$("#password").keyup(function(){
				$("#password").attr("style","border-color:#e4e4e4;");
				$("#validate_password").html("");
			});
			
			$("#signin").click(function(){
				$("#messageControl").removeAttr("class");
				$("#messageControl").empty();
				$("#signin").text("Attendi...");
				if(checkNotEmptyFields()){
					$("#messageControl").html('<center><i class="fa fa-spin fa-2x fa-circle-o-notch" style="font-size:2em;color:#40bbea;"></i></center>');
					$.get("http://localhost:8080/ServerWeb/AuthenticateUserServlet",{username:$("#username").val(),password:$("#password").val()}).done(function(e){
						var parsed = jQuery.parseJSON(e);
						if(parsed.status==0){
							$("#messageControl").attr("class","alert alert-danger");
							$("#messageControl").html("<strong>Spiacente, </strong>le tue credenziali non presenti nel database.");
						}else{
							
							$("#messageControl").empty();
							localStorage.setItem("username",parsed.userName);
							localStorage.setItem("typology",parsed.userType);
							localStorage.setItem("primaryKey",parsed.primaryKey);
							var permission = parsed.classPermission;							
							var myArray = permission.split("-");
							localStorage.setItem("offertaFormativa",myArray[0]);
							localStorage.setItem("gestioneTesi",myArray[1]);
							localStorage.setItem("gestioneTirocinio",myArray[2]);
							localStorage.setItem("dottorato",myArray[3]);
							localStorage.setItem("superAmministratore",myArray[4]);
							
							if($("#rememberMeForLogin").is(':checked')){
								localStorage.setItem("rememberMeForLogin","si");
							}else{
								localStorage.setItem("rememberMeForLogin","no");
							}							
							
							if(localStorage.getItem("typology")=="Studente"){
								var url = 'offertaFormativaStudente.html';
                                window.location.href= url;
							}
							if(localStorage.getItem("typology")=="Professore"){
								var url = 'offertaFormativaProfessore.html';
                                window.location.href= url;
							}
							if(localStorage.getItem("typology")=="Organizzazione"){
								var url = 'gestioneTirocinio&PlacementOrganizzazione.html';
                                window.location.href= url;
							}
							if(localStorage.getItem("typology")=="Amministratore"){
								var url = 'offertaFormativaAmministratore.html';
                                window.location.href= url;
							}
						}
					}).fail(function(e){
						$("#messageControl").attr("class","alert alert-warning");
						$("#messageControl").html("<strong>Spiacenti, </strong> c\'è stato un problema nell\'elaborazione della richiesta. Riprova a breve.");
					});
				}
				$("#signin").text("Sign in");
			});
		});
	</script>

</body>
</html>